package enumandlambda;

/**
 * @author shkstart
 * 使用自定义标识符终止线程
 * @create 2022-12-01-12:41
 */
public class ThreadInterrupet {
    //生明一个自定义的表示符
    private volatile static boolean flag = false;
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
           while (!flag){
               System.out.println("正在转账。。。。。");
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
            System.out.println("差点误大事");
        });
        thread.start();
        Thread.sleep(3000);
        //终止线程
        System.out.println("有内鬼，终止交易");
        flag = true;



    }


}
